﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using StarTrek.Weapon;
using StarTrek.World;

namespace StarTrek.UI.Console.MenuItem
{
    class MenuRepair:iMenuItem
    {
        #region iMenuItem Members

        public bool ProcessSomeRequest(MenuContext Menu, TextWriter sw, TextReader tr)
        {
            bool rVal = (Menu.Action == MenuAction);

            if (rVal)
            {
                //Perform Action
                Galaxy theWorld = Galaxy.Instance;
                iWeapon theWeapon = theWorld.CurrentShip.GetWeapon("Repair");
                float Enegery =0 ;

                if (theWeapon.NeedsEnegery)
                {
                    sw.Write(Properties.Resources.MenuRepairPromptEnegery + Properties.Resources.MenuPrompt);
                    if (!(Single.TryParse(tr.ReadLine(), out Enegery) && (0 <= Enegery)))
                        throw new InvalidDataException(Properties.Resources.MenuAttackErrorEnegery);
                }

                theWeapon.ApplyDefenseToShip(Enegery);

                sw.WriteLine(Menu.wordWrap(Properties.Resources.MenuRepairOut));
                
            }
            return rVal;

        }

        public string MenuAction
        {
            get { return "R"; }
        }

        public string Text
        {
            get { return Properties.Resources.MenuRepairText; }
        }

        public string VerboseText
        {
            get { return Properties.Resources.MenuRepairVerbose; }
        }
        #endregion
    }
}
